$().ready(function() {
	validateRule();
});

$.validator.setDefaults({
	submitHandler : function() {
		update();
	}
});
function update() {
	$.ajax({
		cache : true,
		type : "POST",
		url : "/itm/project/update",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				// parent.reLoad();
				// var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				// parent.layer.close(index);
			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}

function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			name : {
				required : true
			},
			itmProTypeid : {
				required : true
			},
			itmManagerId : {
				required : true
			},
			deptId : {
				required : true
			},
			custName : {
				required : true
			},
			userNames:{
				required : true
			}
		},
		messages : {
			name : {
				required : icon + "请输入项目名称"
			},
			itmProTypeid : {
				required : icon + "请选择项目类型"
			},
			itmManagerId : {
				required : icon + "请选择项目负责人"
			},
			deptId : {
				required : icon + "请选择所属业务部门"
			},
			deptId : {
				required : icon + "请输入客户名称"
			},
			userNames:{
				required : icon + "请选择项目组成员"
			}
		}
	})
}
$(".chosen-select-custName").chosen({
	maxHeight : 200,
	search_contains: true
});

//点击事件
$('.chosen-select-custName').on('change', function(e, params) {
	console.log(params.selected,"111");
	if(params.selected != ""){
		$("#custName").val(params.selected);
	}else{
		$("#custName").val("");
	}


	var opt = {
		query : {
			type : params.selected,
		}
	}
	$('#exampleTable').bootstrapTable('refresh', opt);

});


var openUser = function(){
	layer.open({
		type:2,
		title:"选择人员",
		area : [ '300px', '450px' ],
		content:"/sys/user/treeView"
	})
}

function loadUser(userIds,userNames){
	console.log(userIds);
	console.log(userNames);
	$("#userIds").val(userIds);
	$("#userNames").val(userNames);
}